package com.eshore.norm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eshore.norm.mapper.NormVmSecurityGroupMapper;
import com.eshore.norm.pojo.dto.NormVmSecurityGroup;
import com.eshore.norm.service.NormVmSecurityGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @since 2024-01-12
 */
@Slf4j
@Service
public class NormVmSecurityGroupServiceImpl extends ServiceImpl<NormVmSecurityGroupMapper, NormVmSecurityGroup> implements NormVmSecurityGroupService {

    @Override
    public void sync(Long configId, List<NormVmSecurityGroup> vmSecurityGroups) {
        //清除现在库有的中间关系
        lambdaUpdate().eq(NormVmSecurityGroup::getConfigId,configId).remove();
        //入库
        saveBatch(vmSecurityGroups);
        //TODO 同步到CMDB
        log.info("TODO 同步到CMDB,目前还没有写代码");
    }


    @Override
    public List<String> getFloatipIdByVmId(String vmId) {
        return lambdaQuery()
                .eq(NormVmSecurityGroup::getVmId,vmId)
                .list()
                .stream()
                .map(NormVmSecurityGroup::getSecurityGroupId)
                .collect(Collectors.toList());
    }
}
